<?php
session_start();
require_once($_SERVER['DOCUMENT_ROOT']."/apps/class/transaction.php");
//$_SESSION['username'] =  'zerosottozero@gmail.com';
$description= $_POST['description'];
$value = $_POST['value'];
$type = 0;
$action = $_POST['action'];
$account = $_POST['account'];
if(isset($_POST['category'])){
  $category_par = $_POST['category'];
  $category = unserialize( $category_par );
}
//$account = "123";

echo $category;

try{
if($action == "ADD"){
  $transaction = new transaction();
  $transaction->set_transaction_mandatory($description,$value,$account,$type);
  if(isset($category)){
  $transaction->set_category($category);
  }  
  $transaction->commit_transaction();
}

if($action == "DELETE"){
  $account = new account($result);
}

if($action == "MODIFY"){
  $result = account::create_account_in_db($description,$currency);  
}

if($action == "LIST"){
  $accounts = new accounts('json');
  $result = $accounts->get_list_accounts();
  echo $result;
}

} catch (Exception $e){
  echo $e->getMessage();
}






?>